# models/request_log.py
from sqlalchemy import Column, Integer, String, DateTime, Text
from sqlalchemy.sql import func
from db.base import Base

class RequestLog(Base):
    __tablename__ = "request_logs"

    id = Column(Integer, primary_key=True, index=True)
    method = Column(String(10), nullable=False)
    path = Column(String(200), nullable=False)
    status_code = Column(Integer, nullable=False)
    process_time = Column(Integer, nullable=False)  # 毫秒
    username = Column(String(50), nullable=True)    # 关联用户（未登录时为 None）
    message = Column(Text, nullable=True)           # 自定义信息（如登录失败）
    created_at = Column(DateTime(timezone=True), server_default=func.now())
